<!-- 客服管理 -->
 <template>
  <div class="customer-service">
    <h3>客服管理</h3>

    <!-- 操作按钮 -->
    <div class="actions">
      <el-button type="primary" @click="showAddDialog">新增客服</el-button>
    </div>

    <!-- 筛选查询 -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="客服姓名">
        <el-input v-model="name" placeholder="请输入客服姓名"></el-input>
      </el-form-item>
      <el-form-item label="工号">
        <el-input v-model="employeeId" placeholder="请输入工号"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="status" placeholder="请选择状态">
          <el-option label="全部" value=""></el-option>
          <el-option label="在职" value="active"></el-option>
          <el-option label="离职" value="inactive"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 客服人员列表 -->
    <el-table :data="tableData" style="width: 100%; margin-top: 20px;">
      <el-table-column prop="name" label="客服姓名" width="180"></el-table-column>
      <el-table-column prop="employeeId" label="工号" width="180"></el-table-column>
      <el-table-column prop="contact" label="联系方式" width="180"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template #default="scope">
          <el-tag :type="scope.row.status === 'active' ? 'success' : 'info'">{{ scope.row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template #default="scope">
          <el-button @click="editCustomerService(scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="deleteCustomerService(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 新增/编辑客服对话框 -->
    <el-dialog v-model="dialogVisible" :title="dialogTitle">
      <el-form :model="customerServiceForm">
        <el-form-item label="客服姓名">
          <el-input v-model="customerServiceForm.name"></el-input>
        </el-form-item>
        <el-form-item label="工号">
          <el-input v-model="customerServiceForm.employeeId"></el-input>
        </el-form-item>
        <el-form-item label="联系方式">
          <el-input v-model="customerServiceForm.contact"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="customerServiceForm.status" placeholder="请选择状态">
            <el-option label="在职" value="active"></el-option>
            <el-option label="离职" value="inactive"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveCustomerService">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';

const name = ref('');
const employeeId = ref('');
const status = ref('');
const tableData = ref([
  {
    id: 1,
    name: '张三',
    employeeId: 'CS001',
    contact: '13800138000',
    status: 'active'
  },
  // 其他客服数据...
]);

const dialogVisible = ref(false);
const dialogTitle = ref('新增客服');
const customerServiceForm = ref({
  id: null,
  name: '',
  employeeId: '',
  contact: '',
  status: ''
});

const showAddDialog = () => {
  dialogTitle.value = '新增客服';
  customerServiceForm.value = {
    id: null,
    name: '',
    employeeId: '',
    contact: '',
    status: ''
  };
  dialogVisible.value = true;
};

const editCustomerService = (row) => {
  dialogTitle.value = '编辑客服';
  customerServiceForm.value = { ...row };
  dialogVisible.value = true;
};

const deleteCustomerService = (row) => {
  ElMessageBox.confirm(`确定要删除客服《${row.name}》吗？`, '提示').then(() => {
    // 删除逻辑
    ElMessage.success('删除成功');
  });
};

const onSubmit = () => {
  console.log('查询条件:', name.value, employeeId.value, status.value);
};

const saveCustomerService = () => {
  if (customerServiceForm.value.id) {
    // 编辑逻辑
    ElMessage.success('编辑成功');
  } else {
    // 新增逻辑
    ElMessage.success('新增成功');
  }
  dialogVisible.value = false;
};
</script>

<style scoped>
.customer-service {
  padding: 20px;
}

.actions {
  margin-bottom: 20px;
}
</style>